package cj.web.yc.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.yc.domain.WatchHistory;

/**
 * 
 * @author 
 *
 */
@DAO
public interface WatchHistoryDAO{
	
	@SQL("SELECT a.*,b.name as memberName,c.name as videoName,c.url as videoUrl FROM WatchHistory a "
			+ " left join Member b on a.memberId = b.id "
			+ " left join Video c on a.videoId =c.id WHERE 1=1 "
		    + " #if(:t.memberName != null){ AND b.name LIKE '%##(:t.memberName)%' } "
        	+ " #if(:t.videoName != null){ AND c.name LIKE '%##(:t.videoName)%' } "
			+ " ORDER BY createAt DESC LIMIT :t.start,:t.length ")
    List<WatchHistory> query(@SQLParam("t") WatchHistory watchHistory);
	
	@SQL("SELECT count(1) FROM WatchHistory a "
			+ " left join Member b on a.memberId = b.id "
			+ " left join Video c on a.videoId =c.id WHERE 1=1 "
		    + " #if(:t.memberName != null){ AND b.name LIKE '%##(:t.memberName)%' } "
        	+ " #if(:t.videoName != null){ AND c.name LIKE '%##(:t.videoName)%' } ")
    int querySize(@SQLParam("t") WatchHistory watchHistory);
    
    @SQL("select * from WatchHistory where id=:1 ")
    WatchHistory queryById(int id);
    
    @SQL("INSERT INTO WatchHistory (memberId,videoId,createAt) VALUES (:t.memberId,:t.videoId,:t.createAt) ")
    void create(@SQLParam("t") WatchHistory watchHistory);
}